// 公共详情页
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pagepoint: "", //页面标识
        detailData: {}, //详情数据
        monidata:{
            iID: 4,
            sTitle: "XXX同志",
            sIntroduction: "XXX同志再退休后，积极践行党员的职责和义务，为社区居民服务。",
            sContent: "PHA+PGVtYmVkIHR5cGU9ImFwcGxpY2F0aW9uL3gtc2hvY2t3YXZlLWZsYXNoIiBjbGFzcz0iZWR1aS1mYWtlZC12aWRlbyIgcGx1Z2luc3BhZ2U9Imh0dHA6Ly93d3cubWFjcm9tZWRpYS5jb20vZ28vZ2V0Zmxhc2hwbGF5ZXIiIHNyYz0iaHR0cHM6Ly95Zy53Znlpemhhbi5jb20vc3RyZWV0L2ZpbGVzL3VwbG9hZC8yMDIyMDMwNzAwMDAwMS5tcDQiIHdpZHRoPSIzNTAiIGhlaWdodD0iMjgwIiB3bW9kZT0idHJhbnNwYXJlbnQiIHBsYXk9InRydWUiIGxvb3A9ImZhbHNlIiBtZW51PSJmYWxzZSIgYWxsb3dzY3JpcHRhY2Nlc3M9Im5ldmVyIiBhbGxvd2Z1bGxzY3JlZW49InRydWUiLz48L3A+",
            sSources: 333,
            sVideos: "视频资源ID",
            iTime: 1646290050,
            iEditTime: "编辑时间",
            iNumShare: 5,
            iNumComment: 999,
            iNumzan: 156,
            iZan: 0,
            iReadNum: 10,
            iUID: "发布者ID"
        }
    },

    /**
     * 生命周期函数--监听页面加载
     * 公共详情页参数规则：
     *      1-使用配置档news->api-detail->post，所传参数名须保持一致
     *      2-自定义接口请求，需要传递apiname参数及post参数( wx.$to_encodeBase64(wx.$to_encode(你的json)) )
     */
    onLoad: function (options) {
        var _this = this;
        var pagepoint = options.pagepoint;//页面标识
        if(pagepoint != null && pagepoint != undefined){
            if(options.id != null && options.id != undefined){
                var api_common_news = app.globalData.api_common_news;
                if (api_common_news.hasOwnProperty(pagepoint)) {
                    _this.setData({ //更新页面标识
                        pagepoint: pagepoint,
                        pagename: api_common_news[pagepoint]['sTitle']+"详情"
                    })
                    //检测是否存在detail接口
                    if(api_common_news[pagepoint]['sDetailApi'] != "" && api_common_news[pagepoint]['sDetailApi'] != undefined){
                        //检测是否存在自定义字段
                        var detailObj = {}
                        if(api_common_news[pagepoint]['sDetailPost'] != ""){
                            detailObj[api_common_news[pagepoint]['sDetailPost']] = options.id;
                        }else{
                            detailObj['iID'] = options.id;
                        }
                        //请求接口
                        wx.$requestApi(api_common_news[pagepoint]['sDetailApi'], detailObj, function(res){
                            if (res.code == 0) {
                                _this.setData({
                                    detailData: res.data
                                })
                            } else {
                                wx.$gcs_showToast(res.msg);
                            }
                        })
                    }else{
                        wx.$gcs_showToast("详情数据配置错误");
                    }
                } else {
                    wx.$gcs_showToast("不存在的页面标识");
                }
            }else{
                wx.$gcs_showToast("缺少详情信息-iID");
            }
        }else{
            wx.$gcs_showToast("缺少页面标识");
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})